package com.example.lenovo.a203_yhy_ordering_3.fragments;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.lenovo.a203_yhy_ordering_3.R;
import com.example.lenovo.a203_yhy_ordering_3.activity.SearchResultActivity;
import com.example.lenovo.a203_yhy_ordering_3.beans.FoodInfoBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.FoodListBean;
import com.example.lenovo.a203_yhy_ordering_3.listener.SearchListener;
import com.example.lenovo.a203_yhy_ordering_3.model.SearchModel;

import java.io.Serializable;
import java.util.List;

public class SearchFragment extends Fragment {
    private EditText ed_sea;
    private Button but_sea;
    private String search;
    private List<FoodListBean> foodListBeans;

    public SearchFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return  inflater.inflate(R.layout.activity_search_fragment,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        ed_sea=view.findViewById(R.id.editText8);
        but_sea=view.findViewById(R.id.button5);

        but_sea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                search = ed_sea.getText().toString();
//                SearchModel searchModel = new SearchModel();
//                searchModel.getSearchResult(search,searchListener);

//                Intent intent = new Intent(getActivity(),SearchResultActivity.class);
//                startActivity(intent);

                search = ed_sea.getText().toString();
                System.out.println("搜索的内容------------------------"+search);
                Intent intent = new Intent(getActivity(),SearchResultActivity.class);
                intent.putExtra("search",search);
                startActivity(intent);
            }
        });
    }

//    SearchListener searchListener = new SearchListener() {
//        @Override
//        public void onResponse(List<FoodListBean> foodListBean) {
//            foodListBeans=foodListBean;
//            Intent intent = new Intent(getContext(), SearchResultActivity.class);
//            intent.putExtra("foodBeans",(Serializable) foodListBeans);
//            startActivity(intent);
//        }
//
//        @Override
//        public void onFail(String msg) {
//            Toast.makeText(getContext(),msg,Toast.LENGTH_SHORT).show();
//        }
//    };


}
